*******************************************************************************************
*******STATA ALGORITHM FOR VISQOL DIMENSION OF THE AQOL-7D INSTRUMENT FOR GENERAL POPULATION (WITH MISSING VALUES)    (CHE version 5  date 30 November 2016) ****
**********************************************************************************
* THIS ALGORITHM (CHE version 5 date 30 Nomember 2016) MAY BE CHANGED WITHOUT NOTICE.
* RESEARCHERS SHOULD CHECK WITH THE AQOL GROUP AT MONASH UNIVERSITY
* FOR ANY MODIFICATION www.aqol.com.au***
**********************************************************************************
 *This file analyses the six items of the VisQoL dimension (the 7th dimension) of the AQoL-7D instrument and produces a VisQoL Dimension Value (not utility) which is 
** then mapped to produce a PREDICTED AQoL-7D UTILITY.
***(Dimension scores are referred to as 'values' and 'disvalues' and are NOT utility scores as they have not been evaluated on a life-death scale).*
** If you have complete AQoL-7D data, use the AQoL-7D algorithm to obtain dimension values (not utilities) and the overall utility score.
** If necessary contact angelo.iezzi@monash.edu
***************************************************************
** Variable names: The AQoL-7D has 26 items; the last dimension, VisQol, covers items 21, 22,23,24,25 and 26. For this algorithm, the variables in your questionnaire 
** or database should be named "aqol21, aqol22, aqol23, aqol24, aqol25,aqol26".
**Data entry: The first response in any item, the item best, is entered as 1, the second as 2, third as 3 and so on except for items 23 and 24. 
**In item 24 response level 7 is scored the same as level 2 (0.018) and in item 24 response level 6 is scored the same as response 1 (o.o)
   
*************************************************************
* The dimensions are scaled on a  "Dimension Worst Health State - Dimension Best Health State" scale
*  where DWHS = 0.00 and DBHS = 1.00. 
*************************************************************
*Missing Values: Note that missing data are represented by a blank and are handled by imputing values within the dimension.
*This algorithm allows for 2 missing values.
*However, if more item responses in the  dimension are missing the observations will be dropped and there will not be a dimension score.
**********************************************************************************
* aqol# are item responses in your data
* dvQ# are item disvalues 
* Missing values represented by a blank or dot.**



g Q21 = aqol21
g Q22 = aqol22
g Q23 = aqol23
g Q24 = aqol24
g Q25 = aqol25
g Q26 = aqol26

*****************************************************************
 *********    Imputing Values Missing in Database     *********


********************************
*** Visqol - Dimension 7 *****
********************************

egen DVIS_miss = rowmean(Q21 Q22 Q23 Q24 Q25 Q26)
egen DVISmissno = rowmiss(Q21 Q22 Q23 Q24 Q25 Q26)

replace Q21=round(DVIS_miss) if missing(Q21) & DVISmissno <3
replace Q22=round(DVIS_miss) if missing(Q22) & DVISmissno <3
replace Q23=round(DVIS_miss) if missing(Q23) & DVISmissno <3
replace Q24=round(DVIS_miss) if missing(Q24) & DVISmissno <3
replace Q25=round(DVIS_miss) if missing(Q25) & DVISmissno <3
replace Q26=round(DVIS_miss) if missing(Q26) & DVISmissno <3

*********ITEM DISVALUES*********


***Dimension 7. Visqol

***21. Injure
generate dvQ21=0 if Q21==1
replace dvQ21=0.096 if Q21==2
replace dvQ21=0.386 if Q21==3
replace dvQ21=0.687 if Q21==4
replace dvQ21=1 if Q21==5

***22. Cope with demands
generate dvQ22=0 if Q22==1
replace dvQ22=0.019 if Q22==2
replace dvQ22=0.143 if Q22==3
replace dvQ22=0.360 if Q22==4
replace dvQ22=0.751 if Q22==5
replace dvQ22=1 if Q22==6

***23. Friendships
generate dvQ23=0 if Q23==1
replace dvQ23=0.018212 if Q23==2
replace dvQ23=0.226340 if Q23==3
replace dvQ23=0.505963 if Q23==4
replace dvQ23=0.764346 if Q23==5
replace dvQ23=1 if Q23==6
replace dvQ23=0.018212 if Q23=7

***24. Assistance
generate dvQ24=0 if Q24==1
replace dvQ24=0.093 if Q24==2
replace dvQ24=0.295 if Q24==3
replace dvQ24=0.683 if Q24==4
replace dvQ24=1 if Q24==5
replace dvQ24=0 if Q24==6

***25. Roles
generate dvQ25=0 if Q25==1
replace dvQ25=0.014 if Q25==2
replace dvQ25=0.142 if Q25==3
replace dvQ25=0.377 if Q25==4
replace dvQ25=0.733 if Q25==5
replace dvQ25=1 if Q25==6


***26. Confidence
generate dvQ26=0 if Q26==1
replace dvQ26=0.012 if Q26==2
replace dvQ26=0.1291 if Q26==3
replace dvQ26=0.342 if Q26==4
replace dvQ26=0.670 if Q26==5
replace dvQ26=1 if Q26==6


******************* MODELLING DIMENSION **************
***************************************************


***DIMENSION 7 - VISQOL
**DIMENSION SCALING CONSTANT kD7=-0.833
***VIS HAS 6 ITEMS
***ITEM WORST WEIGHTS (Wi) 
*w21= 0.2696557
* w22= 0.3697268 
* w23= 0.3078306
* w24= 0.2971339 
* w25= 0.3286885 
* w26= 0.2810792 

generate dD7score=(1/-0.833)*[(1+(-0.833*0.2696557*dvQ21))*(1+(-0.833*0.3697268*dvQ22))*(1+(-0.833*0.3078306*dvQ23))*(1+(-0.833*0.2971339*dvQ24))*(1+(-0.833*0.3286885*dvQ25))*(1+(-0.833*0.2810792*dvQ26))-1]

**Item Scores
generate INJURE=1-dvQ21
generate COPE=1-dvQ22
generate FRIENDSHIPS=1-dvQ23
generate ASSISTANCE=1-dvQ24
generate ROLES=1-dvQ25
generate CONFIDENCE=1-dvQ26


generate D7score=1-dD7score
label var D7score "VisqolDimensionScore"

      

